package com.itshare.video.mapper;

import com.itshare.video.pojo.po.Permission;
import com.itshare.video.pojo.po.PermissionExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface PermissionMapper {
    long countByExample(PermissionExample example);

    int deleteByExample(PermissionExample example);

    @Delete({
        "delete from t_permission",
        "where permission_id = #{permissionId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer permissionId);

    @Insert({
        "insert into t_permission (permission_name, available, ",
        "resource_type, message)",
        "values (#{permissionName,jdbcType=VARCHAR}, #{available,jdbcType=INTEGER}, ",
        "#{resourceType,jdbcType=VARCHAR}, #{message,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="permissionId", before=false, resultType=Integer.class)
    int insert(Permission record);

    int insertSelective(Permission record);

    List<Permission> selectByExampleWithRowbounds(PermissionExample example, RowBounds rowBounds);

    List<Permission> selectByExample(PermissionExample example);

    @Select({
        "select",
        "permission_id, permission_name, available, resource_type, message",
        "from t_permission",
        "where permission_id = #{permissionId,jdbcType=INTEGER}"
    })
    @ResultMap("com.itshare.video.mapper.PermissionMapper.BaseResultMap")
    Permission selectByPrimaryKey(Integer permissionId);

    int updateByExampleSelective(@Param("record") Permission record, @Param("example") PermissionExample example);

    int updateByExample(@Param("record") Permission record, @Param("example") PermissionExample example);

    int updateByPrimaryKeySelective(Permission record);

    @Update({
        "update t_permission",
        "set permission_name = #{permissionName,jdbcType=VARCHAR},",
          "available = #{available,jdbcType=INTEGER},",
          "resource_type = #{resourceType,jdbcType=VARCHAR},",
          "message = #{message,jdbcType=VARCHAR}",
        "where permission_id = #{permissionId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Permission record);
}